<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet" href="layuiadmin/plugins/dtree/dtree/dtree.css">
<style type="text/css">
.layui-table-tool {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 50px;
    line-height: 30px;
    padding: 10px 15px;
    border-width: 0 0 1px;
}
</style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <form class="layui-form" lay-filter="myform" id="myform">
                	<input type="reset" id="btReset" class="layui-hide" >
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">选择试卷</label>
                            <div class="layui-input-inline">
                                <input type="text" name="paperName" id="paperName"  autocomplete="off" class="layui-input" select>
                                <input type="hidden" name="paperId" id="paperId">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">考生</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userName" id="userName"  autocomplete="off" class="layui-input" select>
                                <input type="hidden" name="userId" id="userId">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">成绩</label>
                            <div class="layui-input-inline">
                                <select name="markLevel" id="markLevel"></select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">参赛队</label>
                            <div class="layui-input-inline">
                            <ul id="nodeOrgId" name="nodeOrgId" class="dtree" data-id="0" ></ul>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group">
                                <button type="button" class="layui-btn layui-btn-normal" data-type="query"><i class="layui-icon">&#xe615;</i>查询</button>
                                <button type="button" class="layui-btn layui-btn-primary" data-type="resetBtn"><i class="layui-icon">&#xe669;</i>重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="layui-hide"  id="main-table" lay-filter="main-table"></table>
            </div>
        </div>
    </div>
</div>

<script th:inline="none"></script>

<script>
layui.link('layuiadmin/plugins/layui_complete-master/autocomplete.css'); 
layui.extend({
	autocomplete: '{/}layuiadmin/plugins/layui_complete-master/autocomplete' 
});
layui.extend({ 
	dtree: '{/}layuiadmin/plugins/dtree/dtree/dtree'
});
let userId = `[[${session.me.id}]]`;
layui.use(['table','form','element','autocomplete','dtree'], function(){
    var table = layui.table,
    element = layui.element,
    dtree = layui.dtree,
    $ = layui.$,
    autocomplete = layui.autocomplete,
    form = layui.form;
    setAutocomplete('user/getPageList?page=1&limit=20',autocomplete,"userName",'{{d.name}}','{{d.name}}',"setName");
  	window.setName = function(data){
  		$("#userId").val(data.id);
  		$("#userName").val(data.name);
  	}
  	var orgTree = dtree.renderSelect({
  	  elem: "#nodeOrgId",
  	  url: "org/getDTree",
  	  checkbar: false ,
  	  selectTips: "选择部门",
  	  done:function(a,b,c){

  	  }
    });
  	createSelect("mark-level","markLevel",form);
  	$("#paperName").on("click",function(){
  	    top.layer.open({
            id:"openwin",
            type: 2,
            title:'选择试卷',
            area:['1300px','750px'],
            content:  'rooter?url=ksxt/stat/paper-select',
            btn:['选择','关闭'],
            yes:function(index,layero){
            	var iframeWin = top[layero.find('iframe')[0]['name']];
            	let r = iframeWin.getId();
            	$("#paperId").val(r.id);
            	$("#paperName").val(r.name);
            	top.layer.close(index);
            }
        });
  	})
    table.render({
            elem: '#main-table'
            ,height: (top.height-85)+'px'
            ,url: 'paperCopy/getPageList'
            ,title: '考试列表'
            ,page: true 
            ,limit:18
            ,cols: [
                [ 
                {type: 'checkbox'}
                ,{field: 'name', title: "试卷名称",width:280,templet:function(d){
                	return "<a class='colum-link' href='javascript:void(0)' onclick='edit(\""+d.id+"\",\"" + d.name + "\" , this)'>" + d.name + "</a>";
                }}
                ,{field: 'createUserName',title: "考生",width:110}
                ,{field: 'orgName',title: "参赛队",width:110}
                ,{field: 'yearmonth',title: "月度",width:90}
                ,{field: 'weekNo',title: "第几周",width:90}
                ,{field: 'createTime',title: "开考时间",width:170}
                ,{field: 'submitTime',title: "交卷时间",width:170}
                ,{field: 'costMinuteTxt',title: "考试时长",width:90}
                ,{field: 'score',title: "总分",width:90}
                ,{field: 'resultScore',title: "得分",width:90}
                ,{field: 'markLevelTxt',title: "成绩",width:80}
            ]
            ]
            ,done:function(){
          	  enableRowClick(table,form,'main-table',"main-table");
             }
        });
        //头工具栏事件
        table.on('toolbar(main-table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); 
            switch(obj.event){
                case 'edit':
                    var data2 = checkStatus.data;
                    if(data2.length>0){
                        edit(data2[0].id);
                    }else{
                        layer.msg("请选择操作数据！")
                    }
                    break;
            };
        });
        var $ = layui.$, active = {
            query: function(){
            	let orgId = $(":input[name=nodeOrgId_select_nodeId]").val();
                table.reload("main-table",{where:{paperId:$("#paperId").val(),userId: $("#userId").val(),markLevel: $("#markLevel").val(),orgId: orgId}})
            },
            resetBtn:function () {
                $("#btReset").click();
                
            }
        };
        window.loadGrid = function(tableName){
            table.reload(tableName);
        }
        $('.layui-form .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
    function edit(id){
    	top.layer.open({
            id:"openwin",
            type: 2,
            title:'查看答卷',
            area:['1300px','750px'],
            content:  'paperCopy/toResultPage?paperCopyId='+id,
            btn:['关闭']
        });
    }
    
</script>
<script type="text/html" id="toolbarPrice">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-addition"></i>增加</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="mock"><i class="layui-icon layui-icon-login-qq"></i>模拟考试</button>
    </div>
</script>
</body>
</html>